<?php

//
// Stone大叔💯 
// ============================================================================
// ----------------------------------------------------------------------------
// <><><><><><><><><><><><><>有妹子加微信不哦！~<><><><><><><><><><><><><><><><>
// ----------------------------------------------------------------------------
// ============================================================================
// $Author: Stone大叔💯 $
// $Z Stone大叔💯 $
//

namespace Stone\Core;
use Stone\Library\Template;

abstract class Action {
    protected $_view =   null;
    
    public function __construct() {
        $this->_view     =   new Template();
    }
    
    
    
    protected function display($template = null, $cache_id = null, $compile_id = null, $parent = null) {                        
        $template  =   $this->templateExists($template);         
        $this->_view->display($template, $cache_id , $compile_id , $parent);        
    } 
    //模板赋值
    protected function assign($tpl_var, $value = null, $nocache = null){
        $this->_view->assign($tpl_var, $value, $nocache);
    }
    
    // 取得输出内容
    protected function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false) 
    {
        $template  =   $this->templateExists($template);        
        return $this->_view->fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter);
    }
    
    //检查模板 是否已缓存
    protected function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) // 检查模板是否已经缓存
    {
        $template  =   $this->templateExists($template);        
        return $this->_view->isCached($template, $cache_id, $compile_id, $parent);
    }
    
    //检查模板
    private function templateExists($template = null){  
        if($template == null)
            $template    = ACTION . C('TMPL_TEMPLATE_SUFFIX');        
        if(strstr($template, "/") === false)
                $template    =   CONTROLLER . DIRECTORY_SEPARATOR . $template;    
        if(!$this->_view->templateExists($template))
        {
            E("模板不存在:".$template);
        }
        return $template;
    }
    
   
}
